package doantotnghiep.daoimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import doantotnghiep.dao.LoginDao;
import doantotnghiep.model.Staff;

public class LoginDaoImpl implements LoginDao {

	@Autowired
	private HibernateTemplate hibernateTemplate;

	@SuppressWarnings("unchecked")
	@Override
	public Staff checkValidAccount(String userName, String passWord) {
		List<Staff> users;
		String para[] = { "username", "pass" };
		Object val[] = { userName, passWord };
		// users =
		// hibernateTemplate.find("from Staff where status = 0 and userName = '"+userName+"' and password = '"+passWord+"'");
		users = hibernateTemplate.findByNamedQueryAndNamedParam("login", para,
				val);
		if (users != null && users.size() != 0) {
			return users.get(0);
		}
		return null;
	}
}
